package com.isunland.managesystem.ui;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.WebView;
import android.widget.TextView;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import com.isunland.managesystem.R;
import com.isunland.managesystem.entity.CompanyEvents;
import com.isunland.managesystem.widget.MultiLinesViewNew;
import com.isunland.managesystem.widget.SingleLineViewNew;

/**
 * 对象功能:
 * 开发公司: 北京信普达系统工程有限公司
 * 开发人员: HuXiaoDan
 * 创建时间: 2017/4/18 10:32
 */
public class CompanyEventsDetailFragment extends Fragment {

  @BindView(R.id.tv_eventsType) SingleLineViewNew tvEventsType;
  @BindView(R.id.tv_happenDate) SingleLineViewNew tvHappenDate;
  @BindView(R.id.tv_happenPlace) SingleLineViewNew tvHappenPlace;
  @BindView(R.id.tv_mainCharge) SingleLineViewNew tvMainCharge;
  @BindView(R.id.tv_participant) SingleLineViewNew tvParticipant;
  @BindView(R.id.wv_content) WebView wvContent;
  @BindView(R.id.tv_remark) MultiLinesViewNew tvRemark;
  @BindView(R.id.tv_regStaffName) SingleLineViewNew tvRegStaffName;
  @BindView(R.id.tv_regDate) SingleLineViewNew tvRegDate;
  @BindView(R.id.tv_checkStaffName) SingleLineViewNew tvCheckStaffName;
  @BindView(R.id.tv_checkDate) SingleLineViewNew tvCheckDate;
  @BindView(R.id.tv_pics) TextView tvPics;
  private CompanyEvents mContent;

  @Override public void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mContent =
        (CompanyEvents) getArguments().getSerializable(CompanyEventsListFragment.EXTRA_VALUE);
  }

  @Nullable @Override
  public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
      @Nullable Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_company_events_detail, container, false);
    ButterKnife.bind(this, view);
    bindData();
    return view;
  }

  private void bindData() {
    tvEventsType.setTextContent(mContent.getEventCategoryName());
    tvHappenDate.setTextContent(mContent.getOccurrenceTime());
    tvHappenPlace.setTextContent(mContent.getPlaceOccurrence());
    tvMainCharge.setTextContent(mContent.getChargeName());
    tvParticipant.setTextContent(mContent.getParticipantName());
    wvContent.getSettings().setDefaultTextEncodingName("UTF -8");
    wvContent.loadData(mContent.getSubjectContent(), "text/html; charset=UTF-8", null);
    tvRemark.setTextContent(mContent.getRemark());
    tvRegStaffName.setTextContent(mContent.getRegStaffName());
    tvRegDate.setTextContent(mContent.getRegDate());
    tvCheckStaffName.setTextContent(mContent.getCheckStaffName());
    tvCheckDate.setTextContent(mContent.getCheckDate());
  }

  public static CompanyEventsDetailFragment newInstance(CompanyEvents content) {
    Bundle args = new Bundle();
    args.putSerializable(CompanyEventsListFragment.EXTRA_VALUE, content);
    CompanyEventsDetailFragment fragment = new CompanyEventsDetailFragment();
    fragment.setArguments(args);
    return fragment;
  }

  @OnClick(R.id.tv_pics) public void onClick() {
    //浏览相关图片
    Intent intent = new Intent(getActivity(), ConmpanyEventsPicsActivity.class);
    intent.putExtra(ConmpanyEventsPicsFragment.EXTRA_ID, mContent.getId());
    startActivity(intent);
  }
}
